<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #box{
        display: flex;
    }
    #box1{
        width: 200px;
        height: 200px;
        border: 2px solid #111;
        background-color:chocolate;
    }
</style>
<body>
    <h1>变色龙</h1>
    <!-- <div id="box"> -->
        <button onclick="btn1()">红</button>
        <button onclick="btn2()">绿</button>
        <button onclick="btn3()">蓝</button>
        <button onclick="btn4()">紫</button>
        <button onclick="btn5()">橙</button>
    <!-- </div> -->
    <div id="box1">

    </div>
</body>
<script>
    var div=document.getElementById('box1')
    var btn=document.getElementsByClassName('button')
    // for(var i=0;i<btn.length;i++){
    //     btn[i].onclick=function(){
    //         console.log(111);
    //     }
    // }
    function btn1(){
        console.log(111);
        box1.style.backgroundColor='red'
    }
    function btn2(){
        console.log(222);
        box1.style.backgroundColor='chartreuse'
    }
    function btn3(){
        console.log(333);
        box1.style.backgroundColor='aqua'
    }
    function btn4(){
        console.log(444);
        box1.style.backgroundColor='blueviolet'
    }
    function btn5(){
        console.log(555);
        box1.style.backgroundColor='chocolate'
    }
</script>

</html>